﻿using Game.FlowField.Aspect;
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;

namespace Game.FlowField.Burst
{
    [BurstCompile]
    public partial struct RemoveBlockEntityJob : IJobEntity
    {
        [ReadOnly]
        public NativeArray<int> RemovingIndexArray;

        public EntityCommandBuffer.ParallelWriter ECB;

        void Execute([ChunkIndexInQuery] int chunkIndex, ref MapBlockAspect mapBlockAspect)
        {
            var removeingIndex = mapBlockAspect.MapBlock.ValueRW.GridIndex;
            if (RemovingIndexArray.Contains(removeingIndex))
            {
                ECB.DestroyEntity(chunkIndex, mapBlockAspect.Self);
            }
        }
    }
}